package com.ydm.myapp001.activity;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.ydm.myapp001.R;

public class DialogActivity extends AppCompatActivity {

    private ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
    }


    /**
     * 事件响应
     * */
    public void eventRepsonse (View v)  {
        switch(v.getId()){
            case R.id.tv_location:
                Log.d("MySelf", "eventRepsonse: R.id.tv_location ");
                showProgress(true, "努力加载中1");
                break;
            case R.id.tv_btn:
                Log.d("MySelf", "eventRepsonse: R.id.tv_btn ");
                showProgress(true, "努力加载中2");
                break;
            default:
                break;
        }
    }

    public void showProgress(boolean flag, String message) {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            mProgressDialog.setCancelable(flag);
            mProgressDialog.setCanceledOnTouchOutside(false);
        }

        mProgressDialog.setMessage(message);
        mProgressDialog.show();
    }

}
